<HTML>
  <BODY onload="go()"></BODY>
  <SCRIPT src="AsyncXMLHttpRequest.js"></SCRIPT>
  <SCRIPT>
    function go() {
      request("http://localhost:1337/Time out");
      request("http://localhost:220");
      request("http://www.example.com/cross-origin");
      request("http://does not exist");
      for (var i = 0; i < 30; i++) {
        request(location + "?" + i);
      }
    }
    function request(url) {
      span = document.createElement("DIV");
      document.body.appendChild(span);
      span.innerHTML = "<B>" + url + "</B>";
      xmlhttp = new AsyncXMLHttpRequest();
      xmlhttp.span = span;
      xmlhttp.onreadystatechange = rs;
      xmlhttp.onload = load;
      xmlhttp.onerror = error;
      xmlhttp.ontimeout = timeout;
      xmlhttp.onfinish = finish;
      xmlhttp.timeout = 1000;
      xmlhttp.open("GET", url);
      xmlhttp.send();
    }
    
    function rs(xmlhttp) {
      xmlhttp.span.innerHTML += " rs:" + xmlhttp.readyState;
    }
    function load(xmlhttp) {
      xmlhttp.span.innerHTML += " load:" + xmlhttp.status;
    }
    function error(xmlhttp) {
      xmlhttp.span.innerHTML += " error:" + xmlhttp.status;
    }
    function timeout(xmlhttp) {
      xmlhttp.span.innerHTML += " timeout:" + xmlhttp.status;
    }
    function finish(xmlhttp) {
      xmlhttp.span.innerHTML += " finished in " + xmlhttp.duration + "ms";
    }
  </SCRIPT>
</HTML>